﻿using Utils;

namespace QQMapSDK
{
    /// <summary>
    /// 
    /// </summary>
    public static class ApiList
    {
        #region PageCls
        private const string QQApiKey = "JRHBZ-B7UW4-N4YUP-XKJJX-7LG2Z-HJF4O";
        #endregion

        #region LocationToAddress 座标转地址
        /// <summary>
        /// 腾讯地图座标转地址
        /// </summary>
        /// <param name="aMapLocation"></param>
        /// <returns></returns>
        public static Models.QQMapResponse<Models.GeoCoderResult>? LocationToAddress(string aMapLocation)
        {
            try
            {
                string apiUrl = "https://apis.map.qq.com/ws/geocoder/v1?";
                string requestUrl = apiUrl + "location=" + aMapLocation + "&key=" + QQApiKey + "&get_poi=1";
                string? result = HttpHelper.HttpGet(requestUrl);

                if (string.IsNullOrEmpty(result)) return null;

                var reqRes = JsonHelper.DeserializeJsonToObject<Models.QQMapResponse<Models.GeoCoderResult>>(result);
                return reqRes;
            }
            catch (Exception ex)
            {
                Log.WriteLog(typeof(ApiList).Name + "->LocationToAddress->", ex.Message);
                return null;
            }
        }
        #endregion

        #region AddressToLocation 地址转座标
        /// <summary>
        /// 腾讯
        /// </summary>
        /// <param name="City"></param>
        /// <param name="Address"></param>
        /// <returns></returns>
        public static Models.QQMapResponse<Models.GeoCoderResult>? AddressToLocation(string City, string Address)
        {
            try
            {
                string apiUrl = "https://apis.map.qq.com/ws/geocoder/v1?";
                string requestUrl = apiUrl + "address=" + City + Address + "&key=" + QQApiKey;
                string? result = HttpHelper.HttpGet(requestUrl);

                if (string.IsNullOrEmpty(result)) return null;

                var reqRes = JsonHelper.DeserializeJsonToObject<Models.QQMapResponse<Models.GeoCoderResult>>(result);
                return reqRes;
            }
            catch (Exception ex)
            {
                Log.WriteLog(typeof(ApiList).Name + "->AddressToLocation->", ex.Message);
                return null;
            }
        }
        #endregion

        #region DriveringSearch 驾车路径规划
        /// <summary>
        /// 腾讯驾车路径规划
        /// </summary>
        /// <param name="oriLocation"></param>
        /// <param name="desLocation"></param>
        /// <param name="starategy"></param>
        /// <returns></returns>
        public static Models.QQMapResponse<Models.DrivingRouteResult>? DriveringSearch(string oriLocation, string desLocation)
        {
            try
            {
                string apiUrl = "https://apis.map.qq.com/ws/direction/v1/driving?";
                string requestUrl = apiUrl + "from=" + oriLocation + "&to=" + desLocation + "&key=" + QQApiKey;
                string? result = HttpHelper.HttpGet(requestUrl);

                if (string.IsNullOrEmpty(result)) return null;

                var reqRes = JsonHelper.DeserializeJsonToObject<Models.QQMapResponse<Models.DrivingRouteResult>>(result);
                return reqRes;
            }
            catch (Exception ex)
            {
                Log.WriteLog(typeof(ApiList).Name + "->DriveringSearch->", ex.Message);
                return null;
            }
        }
        #endregion
    }
}